<template>
  <div id="main">
    <h2>教学督导</h2>

    <div class="head">
      <el-button
        v-if="jurisdiction=='教学主管'"
        type="primary"
        style="margin:20px"
        @click="handleOpen('添加教学督导', 1)"
      >添加教学督导</el-button>
      <el-input
        v-model="searchTableInfo"
        placeholder="请输入搜索内容"
        style="width:240px;float: right;margin:20px;"
      />
    </div>
    <div id="table-area">
      <el-table
        v-loading="listLoading"
        :data="list.slice((currentPage - 1) * pagesize, currentPage * pagesize)"
        border
        fit
        highlight-current-row
      >
        <el-table-column
          label="序号"
          type="index"
          align="center"
        >
          <template scope="scope">
            <span>{{ (currentPage - 1) * pagesize + scope.$index + 1 }}</span>
          </template>
        </el-table-column>

        <el-table-column
          align="center"
          prop="clazzTypeName"
          label="课程类型"
          :formatter="clazzTypeName_toString"
        />

        <el-table-column
          align="center"
          prop="technicalTypeName"
          label="技术类别"
          :formatter="technicalTypeName_toString"
        />

        <el-table-column
          align="center"
          prop="instructionalSupervisionTeacherName"
          label="授课教师"
        />
        <el-table-column
          align="center"
          prop="instructionalSupervisionPrincipalTeacherName"
          label="主责老师"
        />
        <el-table-column
          align="center"
          prop="instructionalSupervisionTeachingSupervisorName"
          label="教学主管"
        />
        <el-table-column
          align="center"
          prop="instructionalSupervisionEventType"
          label="事件类别"
        > <template slot-scope="scope">
            <span v-if="scope.row.instructionalSupervisionEventType=='0'">入学评估</span>
            <span v-if="scope.row.instructionalSupervisionEventType=='1'">方案评估</span>
            <span v-if="scope.row.instructionalSupervisionEventType=='2'">计划评估</span>
            <span v-if="scope.row.instructionalSupervisionEventType=='3'">阶段评估</span>
            <span v-if="scope.row.instructionalSupervisionEventType=='4'">结束评估</span>
            <span v-if="scope.row.instructionalSupervisionEventType=='5'">其他</span>
          </template>
        </el-table-column>
        <el-table-column
          align="center"
          prop="instructionalSupervisionPostUserName"
          label="发起人"
        />
        <el-table-column
          align="center"
          prop="instructionalSupervisionPostTime"
          label="发起时间"
        />
        <el-table-column
          align="center"
          prop="instructionalSupervisionStatus"
          label="状态"
        > <template slot-scope="scope">
            <span v-if="scope.row.instructionalSupervisionStatus=='0'">发起</span>
            <span v-if="scope.row.instructionalSupervisionStatus=='1'">准备</span>
            <span v-if="scope.row.instructionalSupervisionStatus=='2'">执行</span>
            <span v-if="scope.row.instructionalSupervisionStatus=='3'">结束</span>

          </template>
        </el-table-column>
        <el-table-column
          align="center"
          label="操作"
        >
          <template slot-scope="Scope">
            <el-button
              type="primary"
              :icon="jurisdiction=='教学主管'?'el-icon-edit':'el-icon-search'"
              @click="handleOpen('修改计划', 2, Scope.row.instructionalSupervisionId)"
            >{{ jurisdiction=='教学主管'?"编辑":"查看" }}</el-button>
            <!-- <el-button type="danger" icon="el-icon-delete" @click="handleDelete(Scope.row.plansId) ">删除</el-button> -->
          </template>
        </el-table-column>
      </el-table>

      <div id="pages">
        <el-pagination
          :current-page="currentPage"
          :page-sizes="[5, 10]"
          :page-size="pagesize"
          layout="total, sizes,prev, pager, next"
          :total="list.length"
          prev-text="上一页"
          next-text="下一页"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
        />
      </div>
    </div>

    <el-dialog
      v-if="this.jurisdiction == '教学主管'"
      title=""
      :close-on-click-modal="false"
      :visible.sync="dialogFormVisible"
      :before-close="handleClose"
    >

      <el-form
        ref="instructionalSupervision"
        :model="instructionalSupervision"
        label-position="top"
        :rules="rules"
      >
        <el-form-item
          prop="instructionalSupervisionClazzTypeId"
          label="课程类型"
          :label-width="formLabelWidth"
        >
          <!-- <el-input v-model="teachTodo.teachingTodoRelatedPersonnel" autocomplete="off" maxlength="20" show-word-limit /> -->
          <el-select
            v-model="instructionalSupervision.instructionalSupervisionClazzTypeId"
            :disabled="jurisdiction=='教学主管'?false:true"
            placeholder="请选择"
            filterable
            style="width: 100%;"
          >
            <el-option
              v-for="j in ClazzType"
              :key="j.clazzTypeId"
              :value="j.clazzTypeId"
              :label="j.clazzTypeName"
            />
          </el-select>
        </el-form-item>
        <el-form-item
          prop="instructionalSupervisionTechnicalTypeId"
          label="技术类别"
          :label-width="formLabelWidth"
        >
          <!-- <el-input v-model="teachTodo.teachingTodoRelatedPersonnel" autocomplete="off" maxlength="20" show-word-limit /> -->
          <el-select
            v-model="instructionalSupervision.instructionalSupervisionTechnicalTypeId"
            :disabled="jurisdiction=='教学主管'?false:true"
            placeholder="请选择"
            filterable
            style="width: 100%;"
          >
            <el-option
              v-for="j in TechnicalType "
              :key="j.technicalTypeId"
              :value="j.technicalTypeId"
              :label="j.technicalTypeName"
            />
          </el-select>
        </el-form-item>
        <el-form-item
          prop="instructionalSupervisionTeacherId"
          label="授课老师"
          :label-width="formLabelWidth"
        >
          <!-- <el-input v-model="teachTodo.teachingTodoRelatedPersonnel" autocomplete="off" maxlength="20" show-word-limit /> -->
          <el-select
            v-model="instructionalSupervision.instructionalSupervisionTeacherId"
            :disabled="jurisdiction=='教学主管'?false:true"
            placeholder="请选择"
            filterable
            style="width: 100%;"
          >
            <el-option
              v-for="j in staffTeacher"
              :key="j.staffId"
              :value="j.staffId"
              :label="j.String"
            />
          </el-select>
        </el-form-item>
        <el-form-item
          prop="instructionalSupervisionPrincipalTeacherId"
          label="主责老师"
          :label-width="formLabelWidth"
        >
          <!-- <el-input v-model="teachTodo.teachingTodoRelatedPersonnel" autocomplete="off" maxlength="20" show-word-limit /> -->
          <el-select
            v-model="instructionalSupervision.instructionalSupervisionPrincipalTeacherId"
            :disabled="jurisdiction=='教学主管'?false:true"
            placeholder="请选择"
            filterable
            style="width: 100%;"
          >
            <el-option
              v-for="j in staffPrincipal"
              :key="j.staffId"
              :value="j.staffId"
              :label="j.String"
            />
          </el-select>
        </el-form-item>

        <el-form-item
          prop="instructionalSupervisionTeachingSupervisorId"
          label="教学主管"
          :label-width="formLabelWidth"
        >
          <!-- <el-input v-model="teachTodo.teachingTodoRelatedPersonnel" autocomplete="off" maxlength="20" show-word-limit /> -->
          <el-select
            v-model="instructionalSupervision.instructionalSupervisionTeachingSupervisorId"
            :disabled="jurisdiction=='教学主管'?false:true"
            placeholder="请选择"
            filterable
            style="width: 100%;"
          >
            <el-option
              v-for="j in staffSupervisor "
              :key="j.staffId"
              :value="j.staffId"
              :label="j.String"
            />
          </el-select>
        </el-form-item>

        <el-form-item
          prop="instructionalSupervisionEventType"
          label="事件类别"
          :label-width="formLabelWidth"
        >
          <el-select
            v-model="instructionalSupervision.instructionalSupervisionEventType"
            :disabled="jurisdiction=='教学主管'?false:true"
            filterable
            placeholder="请选择"
            style="width: 100%;"
          >
            <el-option
              v-for="j in options"
              :key="j.value"
              :label="j.label"
              :value="j.value"
            />
          </el-select>
        </el-form-item>
        <el-form-item
          prop="instructionalSupervisionEventTitle"
          label="事件标题"
          :label-width="formLabelWidth"
        >
          <el-input
            v-model="instructionalSupervision.instructionalSupervisionEventTitle"
            :disabled="jurisdiction=='教学主管'?false:true"
            autocomplete="off"
            maxlength="20"
            show-word-limit
            style="width: 100%;"
          />
        </el-form-item>
        <el-form-item
          prop="instructionalSupervisionEventDescription"
          label="事件描述"
          :label-width="formLabelWidth"
        >
          <el-input
            v-model="instructionalSupervision.instructionalSupervisionEventDescription"
            :disabled="jurisdiction=='教学主管'?false:true"
            autocomplete="off"
            maxlength="500"
            show-word-limit
            type="textarea"
            :autosize="{ minRows: 2, maxRows: 20 }"
            placeholder="请输入内容"
          />
        </el-form-item>

        <el-form-item
          prop="instructionalSupervisionRelatedPersonnelIDs"
          label="参加人员"
          :label-width="formLabelWidth"
        >
          <!-- <el-input v-model="teachTodo.teachingTodoRelatedPersonnel" autocomplete="off" maxlength="20" show-word-limit /> -->
          <el-select
            v-model="instructionalSupervision.instructionalSupervisionRelatedPersonnelIDs"
            :disabled="jurisdiction=='教学主管'?false:true"
            multiple
            placeholder="请选择"
            filterable
            style="width: 100%;"
          >
            <el-option
              v-for="j in staff"
              :key="j.staffId"
              :value="j.staffId"
              :label="j.String"
            />
          </el-select>
        </el-form-item>
        <el-form-item
          prop="instructionalSupervisionSolution"
          label="解决方案"
          :label-width="formLabelWidth"
        >
          <el-input
            v-model="instructionalSupervision.instructionalSupervisionSolution"
            :disabled="jurisdiction=='教学主管'?false:true"
            autocomplete="off"
            maxlength="500"
            show-word-limit
            type="textarea"
            :autosize="{ minRows: 2, maxRows: 20 }"
            placeholder="请输入内容"
          />
        </el-form-item>

        <el-form-item
          prop="instructionalSupervisionExecutionRecord"
          label="执行记录"
          :label-width="formLabelWidth"
        >
          <el-input
            v-model="instructionalSupervision.instructionalSupervisionExecutionRecord"
            :disabled="jurisdiction=='教学主管'?false:true"
            autocomplete="off"
            maxlength="500"
            show-word-limit
            type="textarea"
            :autosize="{ minRows: 2, maxRows: 20 }"
            placeholder="请输入内容"
          />
        </el-form-item>

        <el-form-item
          prop="instructionalSupervisionEventSummary"
          label="事件总结"
          :label-width="formLabelWidth"
        >
          <el-input
            v-model="instructionalSupervision.instructionalSupervisionEventSummary"
            :disabled="jurisdiction=='教学主管'?false:true"
            autocomplete="off"
            maxlength="500"
            show-word-limit
            type="textarea"
            :autosize="{ minRows: 2, maxRows: 20 }"
            placeholder="请输入内容"
          />
        </el-form-item>
        <el-form-item
          prop="instructionalSupervisionStatus"
          label="状态"
          :label-width="formLabelWidth"
        >
          <el-select
            v-model="instructionalSupervision.instructionalSupervisionStatus"
            :disabled="jurisdiction=='教学主管'?false:true"
            filterable
            placeholder="请选择"
            style="width: 100%;"
          >
            <el-option
              v-for="j in optionsA"
              :key="j.value"
              :label="j.label"
              :value="j.value"
            />
          </el-select>
        </el-form-item>
      </el-form>
      <div
        slot="footer"
        class="dialog-footer"
      >
        <el-button
          v-if="editType == 2 && jurisdiction ==='教学主管' "
          type="primary"
          @click="handleUpdate('instructionalSupervision')"
        >修 改</el-button>
        <el-button
          v-if="editType == 1 && jurisdiction == '教学主管'"
          type="primary"
          @click="handleAddUser('instructionalSupervision')"
        >添 加</el-button>
      </div>
    </el-dialog>
    <el-dialog
      v-if="this.jurisdiction != '教学主管'"
      title=""
      :close-on-click-modal="false"
      :visible.sync="dialogFormVisible"
      :before-close="handleClose"
    >
      <el-form
        ref="instructionalSupervision"
        :model="instructionalSupervision"
        label-position="top"
        :rules="rules"
      >
        <el-form-item
          prop="instructionalSupervisionClazzTypeId"
          label="课程类型"
          :label-width="formLabelWidth"
        >
          <el-tag
            type="info"
            effect="plain"
          >
            {{ KCLX }}
          </el-tag>
        </el-form-item>
        <el-form-item
          prop="instructionalSupervisionTechnicalTypeId"
          label="技术类别"
          :label-width="formLabelWidth"
        >
          <!-- <el-input v-model="teachTodo.teachingTodoRelatedPersonnel" autocomplete="off" maxlength="20" show-word-limit /> -->
          <el-tag
            type="info"
            effect="plain"
          >
            {{ JSLB }}
          </el-tag>
        </el-form-item>
        <el-form-item
          prop="instructionalSupervisionTeacherId"
          label="授课老师"
          :label-width="formLabelWidth"
        >
          <el-tag
            type="info"
            effect="plain"
          >
            {{ SKLS }}
          </el-tag>
        </el-form-item>
        <el-form-item
          prop="instructionalSupervisionPrincipalTeacherId"
          label="主责老师"
          :label-width="formLabelWidth"
        >
          <el-tag
            type="info"
            effect="plain"
          >
            {{ ZZLS }}
          </el-tag>
        </el-form-item>

        <el-form-item
          prop="instructionalSupervisionTeachingSupervisorId"
          label="教学主管"
          :label-width="formLabelWidth"
        >
          <el-tag
            type="info"
            effect="plain"
          >
            {{ JXZG }}
          </el-tag>
        </el-form-item>

        <el-form-item
          prop="instructionalSupervisionEventType"
          label="事件类别"
          :label-width="formLabelWidth"
        >
          <el-tag
            type="info"
            effect="plain"
          >
            {{ SJLB }}
          </el-tag>
        </el-form-item>
        <el-form-item
          prop="instructionalSupervisionEventTitle"
          label="事件标题"
          :label-width="formLabelWidth"
        >
          <el-input
            v-model="
              instructionalSupervision.instructionalSupervisionEventTitle
            "
            readonly
            autocomplete="off"
            maxlength="20"
            show-word-limit
            style="width: 100%"
          />
        </el-form-item>
        <el-form-item
          prop="instructionalSupervisionEventDescription"
          label="事件描述"
          :label-width="formLabelWidth"
        >
          <el-input
            v-model="
              instructionalSupervision.instructionalSupervisionEventDescription
            "
            readonly
            autocomplete="off"
            maxlength="500"
            show-word-limit
            type="textarea"
            :autosize="{ minRows: 2, maxRows: 20 }"
            placeholder="请输入内容"
          />
        </el-form-item>

        <el-form-item
          prop="instructionalSupervisionRelatedPersonnelIDs"
          label="参加人员"
          :label-width="formLabelWidth"
        >
          <el-tag
            v-for="item in CJRY"
            :key="item"
            type="info"
            effect="plain"
          >
            {{ item }}
          </el-tag>
        </el-form-item>
        <el-form-item
          prop="instructionalSupervisionSolution"
          label="解决方案"
          :label-width="formLabelWidth"
        >
          <el-input
            v-model="instructionalSupervision.instructionalSupervisionSolution"
            readonly
            autocomplete="off"
            maxlength="500"
            show-word-limit
            type="textarea"
            :autosize="{ minRows: 2, maxRows: 20 }"
            placeholder="请输入内容"
          />
        </el-form-item>

        <el-form-item
          prop="instructionalSupervisionExecutionRecord"
          label="执行记录"
          :label-width="formLabelWidth"
        >
          <el-input
            v-model="
              instructionalSupervision.instructionalSupervisionExecutionRecord
            "
            readonly
            autocomplete="off"
            maxlength="500"
            show-word-limit
            type="textarea"
            :autosize="{ minRows: 2, maxRows: 20 }"
            placeholder="请输入内容"
          />
        </el-form-item>

        <el-form-item
          prop="instructionalSupervisionEventSummary"
          label="事件总结"
          :label-width="formLabelWidth"
        >
          <el-input
            v-model="
              instructionalSupervision.instructionalSupervisionEventSummary
            "
            readonly
            autocomplete="off"
            maxlength="500"
            show-word-limit
            type="textarea"
            :autosize="{ minRows: 2, maxRows: 20 }"
            placeholder="请输入内容"
          />
        </el-form-item>
        <el-form-item
          prop="instructionalSupervisionStatus"
          label="状态"
          :label-width="formLabelWidth"
        >
          <el-tag
            type="info"
            effect="plain"
          >
            {{ ZT }}
          </el-tag>
        </el-form-item>
      </el-form>
    </el-dialog>
  </div>
</template>
<script>
import { addplans, deleteplans, updateplans } from '@/api/plans'
// import { getAllteachingDiscussion, getteachingDiscussionById } from '@/api/teachingDiscussion'
import { getAll, getAllRecords, getRecordsbyId, getAllRecordsA, updatesupervisor, getAllRecordsAAAA, getAllRecordsByprincipal, addsupervisor } from '@/api/supervision'
import { selectStudent } from '@/api/child'
import { selectstaffTeacher } from '@/api/staff'
import { selectstaff } from '@/api/staff'
import { selectstaffPrincipal, selectstaffSupervisor } from '@/api/staff'
import { validateChineseName, validatePhoneTwo, validateEMail, checkSpecificKey, validateCharacter, btKeyUp, isInteger } from '@/api/validata'
import store from '@/store/index'
export default {
  data () {
    return {
      /**
       * 临时变量
       */
      KCLX: '',
      JSLB: '',
      SKLS: '',
      ZZLS: '',
      JXZG: '',
      SJLB: '',
      CJRY: [],
      ZT: '',
      jurisdiction: '',
      BB: store.getters.userId,
      options: [{
        value: 0,
        label: '入学评审'
      }, {
        value: 1,
        label: '方案评审'
      }, {
        value: 2,
        label: '计划评审'
      }, {
        value: 3,
        label: '阶段评审'
      },
      {
        value: 4,
        label: '结束评审'
      },
      {
        value: 5,
        label: '其他'
      }
      ],
      value: '',

      optionsA: [{
        value: 0,
        label: '发起'
      }, {
        value: 1,
        label: '准备'
      }, {
        value: 2,
        label: '执行'
      }, {
        value: 3,
        label: '结束'
      }],
      valueA: '',

      newinstructionalSupervision: {

      },

      currentPage: 1, // 默认显示页面为1
      pagesize: 5, //    每页的数据条数
      // list: [],

      tableList: [],
      searchTableInfo: '',
      instructionalSupervision: {},
      instructionalSupervisionParticipants: '',
      instructionalSupervisionRelatedPersonnelIDs: '',
      listLoading: false,
      dialogFormVisible: false,
      editType: 1, // 1 添加 2 修改
      child: {},
      staff: {},
      staffSupervisor: {},
      staffPrincipal: {},
      ClazzType: [
        {
          clazzTypeId: 0,
          clazzTypeName: '个训'
        },
        {
          clazzTypeId: 1,
          clazzTypeName: '合训'
        },
        {
          clazzTypeId: 2,
          clazzTypeName: '集体'
        }
      ],
      TechnicalType: [
        {
          technicalTypeId: 1,
          technicalTypeName: '语言'
        },
        {
          technicalTypeId: 2,
          technicalTypeName: '认知'
        },
        {
          technicalTypeId: 3,
          technicalTypeName: '游戏'
        },
        {
          technicalTypeId: 4,
          technicalTypeName: '社交'
        },
        {
          technicalTypeId: 5,
          technicalTypeName: '运动'
        },
        {
          technicalTypeId: 6,
          technicalTypeName: '感统'
        },
        {
          technicalTypeId: 7,
          technicalTypeName: '艺术'
        },
        {
          technicalTypeId: 8,
          technicalTypeName: '融合'
        }
      ],
      staffTeacher: {},
      formLabelWidth: '200px',
      teacher: '',
      rules: {
        instructionalSupervisionClazzTypeId: [
          { required: true, message: '请选择课程类型', trigger: 'blur' }
        ],
        instructionalSupervisionTechnicalTypeId: [
          { required: true, message: '性选择技术类别', trigger: 'blur' }
        ],
        instructionalSupervisionTeacherId: [
          { required: true, message: '请选择授课老师', trigger: 'blur' }
          // {validator:validateChineseName, trigger: ['blur', 'change']},
        ],
        instructionalSupervisionPrincipalTeacherId: [
          { required: true, message: '请选择主责老师', trigger: 'blur' }
          // {validator:validateChineseName, trigger: ['blur', 'change']},
        ],
        instructionalSupervisionTeachingSupervisorId: [
          { required: true, message: '请选择教学主管', trigger: 'blur' }
          // {validator:validateChineseName, trigger: ['blur', 'change']},
        ],
        instructionalSupervisionEventType: [
          { required: true, message: '请选择事件类别', trigger: 'blur' }
          //  {validator:validateChineseName, trigger: ['blur', 'change']},
        ],
        instructionalSupervisionEventTitle: [
          { required: true, message: '事件标题不能为空', trigger: 'blur' }

        ],
        instructionalSupervisionEventDescription: [
          { required: true, message: '描述不能为空', trigger: 'blur' }
          // {validator:validateChineseName, trigger: ['blur', 'change']},
        ],
        instructionalSupervisionRelatedPersonnelIDs: [
          { required: true, message: '请选择相关人员', trigger: 'blur' }
          // {validator:validateChineseName, trigger: ['blur', 'change']},
        ],
        instructionalSupervisionSolution: [
          { required: true, message: '解决方案不能为空', trigger: 'blur' }
          // {validator:validateChineseName, trigger: ['blur', 'change']},
        ],
        instructionalSupervisionExecutionRecord: [
          { required: true, message: '执行记录不能为空', trigger: 'blur' }
          // {validator:validateChineseName, trigger: ['blur', 'change']},
        ],
        instructionalSupervisionEventSummary: [
          { required: true, message: '事件总结不能为空', trigger: 'blur' }
          // {validator:validateChineseName, trigger: ['blur', 'change']},
        ], instructionalSupervisionStatus: [
          { required: true, message: '请选择状态', trigger: 'blur' }
          // {validator:validateChineseName, trigger: ['blur', 'change']},
        ]
      }
    }
  },
  computed: {
    // 根据计算属性模糊搜索
    list () {
      const searchTableInfo = this.searchTableInfo

      if (searchTableInfo) {
        // filter() 方法创建一个新的数组，新数组中的元素是通过检查指定数组中符合条件的所有元素。
        // 注意： filter() 不会对空数组进行检测。
        // 注意： filter() 不会改变原始数组。
        return this.tableList.filter(data => {
          // some() 方法用于检测数组中的元素是否满足指定条件;
          // some() 方法会依次执行数组的每个元素：
          // 如果有一个元素满足条件，则表达式返回true , 剩余的元素不会再执行检测;
          // 如果没有满足条件的元素，则返回false。
          // 注意： some() 不会对空数组进行检测。
          // 注意： some() 不会改变原始数组。
          return Object.keys(data).some(key => {
            // indexOf() 返回某个指定的字符在某个字符串中首次出现的位置，如果没有找到就返回-1；
            // 该方法对大小写敏感！所以之前需要toLowerCase()方法将所有查询到内容变为小写。
            return (
              String(data[key])
                .toLowerCase()
                .indexOf(searchTableInfo) > -1
            )
          })
        })
      }
      return this.tableList
    }
  },
  created () {
    this.jurisdiction = store.getters.roles[0]

    this.fetchData()
    this.getinfo()
  },
  methods: {
    formatSex: function (row, column, cellValue) {
      if (cellValue === '1') {
        return '女'
      } else if (cellValue === '0') {
        return '男'
      }
    },

    formatAge: function (row, column, cellValue) {
      if (cellValue === -1) {
        return '未填写'
      } else {
        return cellValue
      }
    },
    // 每页下拉显示数据
    handleSizeChange: function (size) {
      this.pagesize = size
    },
    // 点击第几页
    handleCurrentChange: function (currentPage) {
      this.currentPage = currentPage
    },
    getinfo: function () {
      selectStudent().then((resp) => {
        this.child = resp.data.records
      })
      selectstaff().then((resp) => {
        this.staff = resp.data.records
      })
      selectstaffTeacher().then((resp) => {
        this.staffTeacher = resp.data.records
      })

      // selectClazzType().then((resp) => {
      //   this.ClazzType = resp.obj
      // })
      // selectTechnicalType().then((resp) => {
      //   this.TechnicalType = resp.obj
      // })
      selectstaffPrincipal().then((resp) => {
        this.staffPrincipal = resp.data.records
      })

      selectstaffSupervisor().then((resp) => {
        this.staffSupervisor = resp.data.records
      })
    },
    handleClick (row) {

    },
    fetchData () {
      this.tableList = []
      this.listLoading = true
      if (this.jurisdiction === '教学主管') {
        getAllRecordsA(this.BB).then(data => {
          this.newinstructionalSupervision
          for (var i = 0; i < data.data.records.length; i++) {
            this.newinstructionalSupervision.clazzTypeName = data.data.records[i].instructionalSupervisionClazzTypeId
            this.newinstructionalSupervision.instructionalSupervisionPostUserName = data.data.records[i].instructionalSupervisionPostUserName
            this.newinstructionalSupervision.technicalTypeName = data.data.records[i].instructionalSupervisionTechnicalTypeId
            this.newinstructionalSupervision.instructionalSupervisionTeachingSupervisorName = data.data.records[i].instructionalSupervisionTeachingSupervisorName
            this.newinstructionalSupervision.instructionalSupervisionTeacherName = data.data.records[i].instructionalSupervisionTeacherName
            this.newinstructionalSupervision.instructionalSupervisionPrincipalTeacherName = data.data.records[i].instructionalSupervisionPrincipalTeacherName
            this.newinstructionalSupervision.instructionalSupervisionPostUserName = data.data.records[i].instructionalSupervisionPostUserName
            this.newinstructionalSupervision.instructionalSupervisionEventType = data.data.records[i].instructionalSupervisionEventType
            this.newinstructionalSupervision.instructionalSupervisionPostTime = data.data.records[i].instructionalSupervisionPostTime
            this.newinstructionalSupervision.instructionalSupervisionStatus = data.data.records[i].instructionalSupervisionStatus
            this.newinstructionalSupervision.instructionalSupervisionId = data.data.records[i].instructionalSupervisionId

            this.tableList.push(this.newinstructionalSupervision)
            this.newinstructionalSupervision = {}
          }

          this.listLoading = false
        })
      } else if (this.jurisdiction === '教学主任') {
        getAllRecordsAAAA(this.BB).then(data => {
          this.newinstructionalSupervision
          for (var i = 0; i < data.data.records.length; i++) {
            this.newinstructionalSupervision.clazzTypeName = data.data.records[i].instructionalSupervisionClazzTypeId
            this.newinstructionalSupervision.instructionalSupervisionPostUserName = data.data.records[i].instructionalSupervisionPostUserName
            this.newinstructionalSupervision.technicalTypeName = data.data.records[i].instructionalSupervisionTechnicalTypeId
            this.newinstructionalSupervision.instructionalSupervisionTeachingSupervisorName = data.data.records[i].instructionalSupervisionTeachingSupervisorName
            this.newinstructionalSupervision.instructionalSupervisionTeacherName = data.data.records[i].instructionalSupervisionTeacherName
            this.newinstructionalSupervision.instructionalSupervisionPrincipalTeacherName = data.data.records[i].instructionalSupervisionPrincipalTeacherName
            this.newinstructionalSupervision.instructionalSupervisionPostUserName = data.data.records[i].instructionalSupervisionPostUserName
            this.newinstructionalSupervision.instructionalSupervisionEventType = data.data.records[i].instructionalSupervisionEventType
            this.newinstructionalSupervision.instructionalSupervisionPostTime = data.data.records[i].instructionalSupervisionPostTime
            this.newinstructionalSupervision.instructionalSupervisionStatus = data.data.records[i].instructionalSupervisionStatus
            this.newinstructionalSupervision.instructionalSupervisionId = data.data.records[i].instructionalSupervisionId

            this.tableList.push(this.newinstructionalSupervision)
            this.newinstructionalSupervision = {}
          }

          this.listLoading = false
        })
      } else if (this.jurisdiction === '医疗主管') {
        getAll(this.BB).then(data => {
          this.newinstructionalSupervision
          for (var i = 0; i < data.data.records.length; i++) {
            this.newinstructionalSupervision.clazzTypeName = data.data.records[i].instructionalSupervisionClazzTypeId
            this.newinstructionalSupervision.instructionalSupervisionPostUserName = data.data.records[i].instructionalSupervisionPostUserName
            this.newinstructionalSupervision.technicalTypeName = data.data.records[i].instructionalSupervisionTechnicalTypeId
            this.newinstructionalSupervision.instructionalSupervisionTeachingSupervisorName = data.data.records[i].instructionalSupervisionTeachingSupervisorName
            this.newinstructionalSupervision.instructionalSupervisionTeacherName = data.data.records[i].instructionalSupervisionTeacherName
            this.newinstructionalSupervision.instructionalSupervisionPrincipalTeacherName = data.data.records[i].instructionalSupervisionPrincipalTeacherName
            this.newinstructionalSupervision.instructionalSupervisionPostUserName = data.data.records[i].instructionalSupervisionPostUserName
            this.newinstructionalSupervision.instructionalSupervisionEventType = data.data.records[i].instructionalSupervisionEventType
            this.newinstructionalSupervision.instructionalSupervisionPostTime = data.data.records[i].instructionalSupervisionPostTime
            this.newinstructionalSupervision.instructionalSupervisionStatus = data.data.records[i].instructionalSupervisionStatus
            this.newinstructionalSupervision.instructionalSupervisionId = data.data.records[i].instructionalSupervisionId

            this.tableList.push(this.newinstructionalSupervision)
            this.newinstructionalSupervision = {}
          }

          this.listLoading = false
        })
      } else if (this.jurisdiction === '责任教师') {
        getAllRecordsByprincipal(this.BB).then(data => {
          this.newinstructionalSupervision
          for (var i = 0; i < data.data.records.length; i++) {
            this.newinstructionalSupervision.clazzTypeName = data.data.records[i].instructionalSupervisionClazzTypeId
            this.newinstructionalSupervision.instructionalSupervisionPostUserName = data.data.records[i].instructionalSupervisionPostUserName
            this.newinstructionalSupervision.technicalTypeName = data.data.records[i].instructionalSupervisionTechnicalTypeId
            this.newinstructionalSupervision.instructionalSupervisionTeachingSupervisorName = data.data.records[i].instructionalSupervisionTeachingSupervisorName
            this.newinstructionalSupervision.instructionalSupervisionTeacherName = data.data.records[i].instructionalSupervisionTeacherName
            this.newinstructionalSupervision.instructionalSupervisionPrincipalTeacherName = data.data.records[i].instructionalSupervisionPrincipalTeacherName
            this.newinstructionalSupervision.instructionalSupervisionPostUserName = data.data.records[i].instructionalSupervisionPostUserName
            this.newinstructionalSupervision.instructionalSupervisionEventType = data.data.records[i].instructionalSupervisionEventType
            this.newinstructionalSupervision.instructionalSupervisionPostTime = data.data.records[i].instructionalSupervisionPostTime
            this.newinstructionalSupervision.instructionalSupervisionStatus = data.data.records[i].instructionalSupervisionStatus
            this.newinstructionalSupervision.instructionalSupervisionId = data.data.records[i].instructionalSupervisionId

            this.tableList.push(this.newinstructionalSupervision)
            this.newinstructionalSupervision = {}
          }

          this.listLoading = false
        })
      } else if (this.jurisdiction === '教务主任') {
        getAll().then(data => {
          this.newinstructionalSupervision
          for (var i = 0; i < data.data.records.length; i++) {
            this.newinstructionalSupervision.clazzTypeName = data.data.records[i].instructionalSupervisionClazzTypeId
            this.newinstructionalSupervision.instructionalSupervisionPostUserName = data.data.records[i].instructionalSupervisionPostUserName
            this.newinstructionalSupervision.technicalTypeName = data.data.records[i].instructionalSupervisionTechnicalTypeId
            this.newinstructionalSupervision.instructionalSupervisionTeachingSupervisorName = data.data.records[i].instructionalSupervisionTeachingSupervisorName
            this.newinstructionalSupervision.instructionalSupervisionTeacherName = data.data.records[i].instructionalSupervisionTeacherName
            this.newinstructionalSupervision.instructionalSupervisionPrincipalTeacherName = data.data.records[i].instructionalSupervisionPrincipalTeacherName
            this.newinstructionalSupervision.instructionalSupervisionPostUserName = data.data.records[i].instructionalSupervisionPostUserName
            this.newinstructionalSupervision.instructionalSupervisionEventType = data.data.records[i].instructionalSupervisionEventType
            this.newinstructionalSupervision.instructionalSupervisionPostTime = data.data.records[i].instructionalSupervisionPostTime
            this.newinstructionalSupervision.instructionalSupervisionStatus = data.data.records[i].instructionalSupervisionStatus
            this.newinstructionalSupervision.instructionalSupervisionId = data.data.records[i].instructionalSupervisionId

            this.tableList.push(this.newinstructionalSupervision)
            this.newinstructionalSupervision = {}
          }

          this.listLoading = false
        })
      } else {
        getAllRecords(this.BB).then(data => {
          this.newinstructionalSupervision
          for (var i = 0; i < data.data.records.length; i++) {
            this.newinstructionalSupervision.clazzTypeName = data.data.records[i].instructionalSupervisionClazzTypeId
            this.newinstructionalSupervision.instructionalSupervisionPostUserName = data.data.records[i].instructionalSupervisionPostUserName
            this.newinstructionalSupervision.technicalTypeName = data.data.records[i].instructionalSupervisionTechnicalTypeId
            this.newinstructionalSupervision.instructionalSupervisionTeachingSupervisorName = data.data.records[i].instructionalSupervisionTeachingSupervisorName
            this.newinstructionalSupervision.instructionalSupervisionTeacherName = data.data.records[i].instructionalSupervisionTeacherName
            this.newinstructionalSupervision.instructionalSupervisionPrincipalTeacherName = data.data.records[i].instructionalSupervisionPrincipalTeacherName
            this.newinstructionalSupervision.instructionalSupervisionPostUserName = data.data.records[i].instructionalSupervisionPostUserName
            this.newinstructionalSupervision.instructionalSupervisionEventType = data.data.records[i].instructionalSupervisionEventType
            this.newinstructionalSupervision.instructionalSupervisionPostTime = data.data.records[i].instructionalSupervisionPostTime
            this.newinstructionalSupervision.instructionalSupervisionStatus = data.data.records[i].instructionalSupervisionStatus
            this.newinstructionalSupervision.instructionalSupervisionId = data.data.records[i].instructionalSupervisionId

            this.tableList.push(this.newinstructionalSupervision)
            this.newinstructionalSupervision = {}
          }

          this.listLoading = false
        })
      }
    },
    handleDelete (id) {
      this.$confirm('确认删除该记录？').then(() =>
        deleteplans(id).then(data => {
          this.$notify({
            title: '操作成功',
            type: 'success'
          })
          const totalPage = Math.ceil(
            (this.tableList.length - 1) / this.pagesize
          )
          const page =
            this.currentPage > totalPage ? totalPage : this.currentPage
          this.currentPage = this.currentPage < 1 ? 1 : page
          this.fetchData()
        })
      )
    },
    handleAddUser (formName) {
      this.$refs[formName].validate(valid => {
        if (valid) {
          for (var i = 0; i < this.instructionalSupervision.instructionalSupervisionRelatedPersonnelIDs.length; i++) {
            this.instructionalSupervisionRelatedPersonnelIDs += this.instructionalSupervision.instructionalSupervisionRelatedPersonnelIDs[i] + ';'
          }
          this.instructionalSupervision.instructionalSupervisionRelatedPersonnelIDs = this.instructionalSupervisionRelatedPersonnelIDs
          addsupervisor(this.instructionalSupervision, this.BB).then(resp => {
            this.$notify({
              title: '操作成功',
              type: 'success'
            })
            this.fetchData()
          })
          this.plans = {}
          this.dialogFormVisible = false
          return true
        } else {
          this.$notify({
            title: '请正确填写',
            type: 'error'
          })
          return false
        }
      })
    },

    handleOpen (title, type, id) {
      this.teachingDiscussion = {}
      this.title = title
      this.editType = type

      if (type === 2) {
        getRecordsbyId(id).then((resp) => {
          this.instructionalSupervision = resp.data.records
          var list = this.instructionalSupervision.instructionalSupervisionRelatedPersonnelIDs
          // list.length -= 1
          for (var i = 0; i < list.length; i++) {
            list[i] = parseInt(list[i])
          }
          this.instructionalSupervision.instructionalSupervisionParticipants = list

          for (let i1 = 0; i1 < this.ClazzType.length; i1++) {
            if (this.instructionalSupervision.instructionalSupervisionClazzTypeId == this.ClazzType[i1].clazzTypeId) {
              this.KCLX = this.ClazzType[i1].clazzTypeName
            }
          }
          for (let i2 = 0; i2 < this.TechnicalType.length; i2++) {
            if (this.instructionalSupervision.instructionalSupervisionTechnicalTypeId == this.TechnicalType[i2].technicalTypeId) {
              this.JSLB = this.TechnicalType[i2].technicalTypeName
            }
          }
          for (let i3 = 0; i3 < this.staffTeacher.length; i3++) {
            if (this.instructionalSupervision.instructionalSupervisionTeacherId == this.staffTeacher[i3].staffId) {
              this.SKLS = this.staffTeacher[i3].String
            }
          }
          for (let i4 = 0; i4 < this.staffPrincipal.length; i4++) {
            if (this.instructionalSupervision.instructionalSupervisionPrincipalTeacherId == this.staffPrincipal[i4].staffId) {
              this.ZZLS = this.staffPrincipal[i4].String
            }
          }
          for (let i5 = 0; i5 < this.staffSupervisor.length; i5++) {
            if (this.instructionalSupervision.instructionalSupervisionTeachingSupervisorId == this.staffSupervisor[i5].staffId) {
              this.JXZG = this.staffSupervisor[i5].String
            }
          }
          for (let i6 = 0; i6 < this.options.length; i6++) {
            if (this.instructionalSupervision.instructionalSupervisionEventType == this.options[i6].value) {
              this.SJLB = this.options[i6].label
            }
          }
          for (let i7 = 0; i7 < this.staff.length; i7++) {
            for (
              let j2 = 0;
              j2 <
              this.instructionalSupervision.instructionalSupervisionRelatedPersonnelIDs
                .length;
              j2++
            ) {
              if (
                this.instructionalSupervision.instructionalSupervisionRelatedPersonnelIDs[
                j2
                ] == this.staff[i7].staffId
              ) {
                this.CJRY.push(this.staff[i7].String)
              }
            }
          }
          for (let i8 = 0; i8 < this.optionsA.length; i8++) {
            if (this.instructionalSupervision.instructionalSupervisionStatus == this.optionsA[i8].value) {
              this.ZT = this.optionsA[i8].label
            }
          }
        })
        this.dialogFormVisible = true
      } else {
        this.dialogFormVisible = true
      }
    },
    handleClose () {
      this.dialogFormVisible = false
      this.instructionalSupervision = {}
    },
    handleUpdate (formName) {
      // this.summary.teachCreatetime = this.summary.teachCreatetime

      this.$refs[formName].validate(valid => {
        if (valid) {
          for (var i = 0; i < this.instructionalSupervision.instructionalSupervisionRelatedPersonnelIDs.length; i++) {
            this.instructionalSupervisionRelatedPersonnelIDs += this.instructionalSupervision.instructionalSupervisionRelatedPersonnelIDs[i] + ';'
          }
          this.instructionalSupervision.instructionalSupervisionRelatedPersonnelIDs = this.instructionalSupervisionRelatedPersonnelIDs
          updatesupervisor(this.instructionalSupervision).then(resp => {
            this.instructionalSupervisionRelatedPersonnelIDs = ''

            this.$notify({
              title: '修改成功',
              type: 'success'
            })
            this.fetchData()
          })
          this.dialogFormVisible = false
          return true
        } else {
          this.$notify({
            title: '请正确填写',
            type: 'error'
          })
          return false
        }
      })
    },
    technicalTypeName_toString (row, column, cellValue) {
      // console.log(this.TechnicalType)
      for (let i = 0; i < this.TechnicalType.length; i++) {
        if (cellValue == this.TechnicalType[i].technicalTypeId - 1) {
          return this.TechnicalType[i].technicalTypeName
        }
      }
    },
    clazzTypeName_toString (row, column, cellValue) {
      // console.log(this.ClazzType)
      for (let i = 0; i < this.ClazzType.length; i++) {
        if (cellValue == this.ClazzType[i].clazzTypeId) {
          return this.ClazzType[i].clazzTypeName
        }
      }
    }
    // getAllJurisdiction() {
    //   getAllJurisdiction().then((resp) => {
    //     this.jurisdiction = resp.obj
    //   })
    // },
  }
}
</script>

<style scoped>
#main {
  margin-left: 5px;
  margin-right: 5px;
}
#table-area {
  margin-left: 10px;
  margin-right: 10px;
}
</style>
